package dud;

import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class DisplayFrame extends JFrame {

    List<DiskPanel> diskPanels = new ArrayList<DiskPanel>();
 
    public DisplayFrame() {
        initFrame();
    }

    private void initFrame() {

        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(DisplayFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(DisplayFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(DisplayFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(DisplayFrame.class.getName()).log(Level.SEVERE, null, ex);
        }

        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setAlwaysOnTop(true);
        this.setUndecorated(true);
        this.setLocation(600, 100);
        this.getContentPane().setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
        this.setSize(new Dimension(400, 0));
        this.setVisible(true);

        /* -- dados de teste */
        //DiskPanel testDiskPanel = new DiskPanel("/", 10000);
        //addDiskPanel(testDiskPanel); 
        
        //setUsed("/", 3000);
        /* dados de teste -- */

        final JFrame esteFrame = this;
        this.addMouseMotionListener(new MouseMotionAdapter() {

            @Override
            public void mouseDragged(MouseEvent e) {
                super.mouseDragged(e);
                esteFrame.setLocation(e.getLocationOnScreen());
            }
        });
    }

    public void addDiskPanel(DiskPanel diskPanel) {
         // = new DiskPanel("/", 10000);
        diskPanels.add(diskPanel);
        this.getContentPane().add(diskPanel);
        this.setSize(this.getSize().width, this.getSize().height + 75);
    }

    public void removeDiskPanel(DiskPanel diskPanel) {
        diskPanels.remove(diskPanel);
        this.getContentPane().remove(diskPanel);
        this.setSize(this.getSize().width, this.getSize().height - 75);
    }

    public void setUsed(String diskName, int usedMegaBytes) {
        for (DiskPanel dp : diskPanels) {
            if (dp.getDiskName().equals(diskName)) {
                dp.setUsedSpace(usedMegaBytes);
            }
        }
    }

}
